import { defineStore } from "pinia";
export const useDirectoryStore = defineStore({
  id: "directoryStore",
  state: () => ({
    directoryList: []
  }),
  actions: {
    addDirectory(item) {
      this.directoryList = item;
    },
    removeDirectory(id) {
      this.directoryList = this.directoryList.filter(
        directoryList => directoryList.id !== id
      );
    },
    getDirectoryById(id) {
      if (localStorage.getItem("directoryStore") != null) {
        let itemList = JSON.parse(
          localStorage.getItem("directoryStore")
        ).directoryList;
        console.log(itemList);
        return itemList.find(item => item.id === Number(id));
      }
      return [];
    }
  },
  persist: {
    strategies: [
      {
        key: "directoryStore",
        storage: localStorage
      }
    ],
    enabled: true
  } // 开启本地缓存
});
